package com.mxpio.erp.common.inventory.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.quality.entity.InspectionBill;
import com.mxpio.erp.common.technology.entity.ItemGroup;
import com.mxpioframework.jpa.annotation.DictAble;
import com.mxpioframework.security.annotation.Dict;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@Table(name = "V_MB_ERP_INV_LOT_STOCK")
@Schema(description="批次库存")
@NoArgsConstructor
@AllArgsConstructor
public class VInvLotStock implements DictAble, Serializable {

	private static final long serialVersionUID = 1L;
	
	public VInvLotStock(String itemCode, String whCode, BigDecimal quantity, BigDecimal borrowedQuantity){
		this.itemCode = itemCode;
		this.whCode = whCode;
		this.quantity = quantity;
		this.borrowedQuantity = borrowedQuantity;
	}
	public VInvLotStock(BigDecimal fee){//合计fee字段
		this.fee = fee;
	}

	//库存汇总，带字段名称
	public VInvLotStock(String itemCode, String whCode,String itemName,String itemGroupCode,String itemSpec,String unitCode,String drawingNo,String imgFile, String whType,BigDecimal quantity,BigDecimal fee, BigDecimal borrowedQuantity){
		this.itemCode = itemCode;
		this.whCode = whCode;
		this.itemName = itemName;
		this.itemGroupCode = itemGroupCode;
		this.itemSpec = itemSpec;
		this.unitCode = unitCode;
		this.drawingNo = drawingNo;
		this.quantity = quantity;
		this.borrowedQuantity = borrowedQuantity;
		this.fee = fee;
		this.imgFile = imgFile;
		this.whType = whType;
		//this.lotStatus = lotStatus;
	}
	@Id
	@Column(name = "ITEM_CODE_")
	@Schema(description = "物料代码")
	private String itemCode;
	
	@Id
	@Column(name = "LOT_NO_")
	@Schema(description = "批次")
	private String lotNo;

	@Id
	@Column(name = "SUB_LOT_INDEX_")
	@Schema(description = "子批次索引号")//无子批默认为0
	private String subLotIndex;
	@Id
	@Column(name = "WH_CODE_")
	@Schema(description = "仓库代码")
	@Dict(dicCode = "whCode" ,dicEntity = Warehouse.class, dicText = "whName")
	private String whCode;
	
	@Column(name = "QUANTITY_")
	@Schema(description = "数量")
	private BigDecimal quantity;
	
	@Column(name = "BORROWED_QUANTITY_")
	@Schema(description = "已借出数量")
	private BigDecimal borrowedQuantity;

	@Column(name = "ITEM_NAME_")
	@Schema(description = "物料名称")
	private String itemName;

	@Column(name = "ITEM_GROUP_CODE_")
	@Schema(description = "物料组")
	@Dict(dicCode="groupCode", dicEntity = ItemGroup.class, dicText = "groupName")
	private String itemGroupCode;

	@Column(name = "ITEM_SPEC_")
	@Schema(description = "物料规格")
	private String itemSpec;

	@Column(name = "UNIT_CODE_")
	@Schema(description = "单位编号")
	@Dict(dicCode="ERP_TECH_UNIT_CODE")
	private String unitCode;

	@Column(name = "IMG_FILE_")
	@Schema(description = "图片路径")
	private String imgFile;

	@Column(name = "FEE")
	@Schema(description = "费用")
	private BigDecimal fee;

	@Column(name = "WH_TYPE_")
	@Schema(description = "仓库类别")
	@Dict(dicCode = "ERP_INV_WH_TYPE")
	private String whType;

	@Column(name = "DRAWING_NO_")
	@Schema(description = "图号")
	private String drawingNo;

	@Column(name = "CREATE_TIME", updatable = false)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Schema(description = "创建时间")
	private Date createTime;

	//lot_status_
	@Column(name = "LOT_STATUS_")
	@Schema(description = "批次状态")
	private String lotStatus;

	@Column(name = "INSPECTION_BILL_NO")
	@Schema(description = "质检单单号")
	private String inspectionBillNo;

	@Transient
	private Map<String, String> textMap;

	@Transient
	@Schema(description = "关联质检单")
	private InspectionBill inspectionBill;

	public String putText(String key, String value) {
		if (textMap == null) {
			textMap = new HashMap<>();
		}
		return textMap.put(key, value);
	}

}
